package com.acme.bankapp.service.bank;

import java.util.ArrayList;
import java.util.List;

import com.acme.domain.bank.Bank;
import com.acme.domain.bank.Client;
import com.acme.domain.bank.ClientExistsException;
import com.acme.domain.bank.ClientPegistrationListener;
import com.acme.domain.bank.NotEnoughFundsException;
import com.acme.domain.bank.OverDraftLimitExceededException;

public class BankService {
	
	public void addClient(Client client, Bank bank, int i, boolean todo) throws ClientExistsException{
		if(todo) {
			List<Client> clients = bank.getClients();
			if (clients.size() != 0)
				for(Client cl: clients)
					if( (client.getName()).equals(cl.getName()) )
						throw new ClientExistsException("Client " +client.getName() + " is already exists");
			bank.getClients().add(client);
			ClientPegistrationListener[] listeners = bank.getListeners();
			for(ClientPegistrationListener listener: listeners)
				listener.onClientAdded(client);
		}
	}

	public void printMaximumAmountToWithdraw(Bank bank){
		ArrayList<Client> clients = bank.getClients();
		for(Client client: clients)
			System.out.println(client.getAccount());
	}
	
	public void printBalance(Bank bank){
		ArrayList<Client> clients = bank.getClients();
		for(Client client: clients)
			System.out.println(client);
	}
	
	public void modifyBank(Bank bank) throws NotEnoughFundsException{
		System.out.println(bank.getClients());
		for(int i = 0; i < 10; i++)
			if(i%2 == 0)
				bank.getClients().get(i).getAccount().deposit(i*2);
			else
				bank.getClients().get(i).getAccount().withdraw(i*7);
	}
	
}
